what happens when you set transform.position in Unity?

您所在的位置:网站首页 unity transform position what happens when you set transform.position in Unity?

what happens when you set transform.position in Unity?

#what happens when you set transform.position in Unity?| 来源: 网络整理| 查看: 265

When you set transform.position in Unity, the engine automatically calculates the corresponding local position the object needs relative to its parent to arrive at that location, and sets its local position there.

When you set transform.localPosition, the local position is updated directly. Subsequent attempts to read transform.position or use any of the Transform's transformation methods will use this new local position - in addition to any parent transforms.

(Don't underestimate your power to find these things out through your own testing - a short script that sets position or localPosition and prints the values of both before and after would have answered most of your question, much faster than waiting for a stranger to reply here!)

In C# code, this would look something like this:

public Vector3 position { get { if (parent == null) return localPosition; return parent.TransformPoint(localPosition); } set { if (parent == null) localPosition = value; else localPosition = parent.InverseTransformPoint(value); hasChanged = true; } }

The reason you don't see this implementation in Visual Studio is likely because this isn't implemented in managed C# code, but in the engine's underlying C++ code, compiled down to a native binary, to which the C# representation just provides a wrapper.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3